#ifndef _TILE_H_
#define _TILE_H_

#ifdef _WIN32
#pragma once
#endif

/**
 * 17.3.12 - Steven Hartin - Fixed constructors, fixed textures
 *
 * 03.03.12 - Steven Hartin - Original Creation
 */
 
class CTile;

#include <string>
#include <algorithm>

#include "d3dx9.h"

#include "devicemanager.h"
#include "displayable.h"
#include "displayablecontainer.h"
#include "meshcontainer.h"
#include "texturecontainer.h"
#include "movable_entity.h"
//#include "game\player.h"
//#include "weapons\weapon.h"
//#include "engine\repeat.h"
#include "constants.h"

class CPickup;

using std::string;

typedef enum TILE_FACE
{
    TILE_FACE_LEFT = 0,
    TILE_FACE_BOTTOM,
    TILE_FACE_TOP,
    TILE_FACE_FRONT,
    TILE_FACE_RIGHT,
    TILE_FACE_BACK
} TILE_FACE;

class CTile : public CMovableEntity
{
public:
    CTile(ENTITY_ID nTileID, short int nHeight, short int nWidth,
                 short int nDepth);
    CTile(ENTITY_ID nTileID, string szTextureName, short int nHeight,
                 short int nWidth, short int nDepth);

    void setDroppable(bool bDropable);
    bool isDroppable() const;

    // **TODO**
    //void setTimeToDrop(double dTimeToDropMilliseconds);
    //double getTimeToDrop() const;

    void setWalkable(bool bWalkable);
    bool isWalkable() const;
    bool isDestructible() const;
    void setDestructible(bool bDestructible);

    virtual void destroy() {}
    bool isBeingDestroyed() const;
    void setDestroyed(bool bValue=true);

    // Events must be declared as virtual to allow correct dynamic binding.

    //virtual void onEnter(CPlayer *pPlayer) {}
    //virtual void onLeave(CPlayer *pPlayer) {}
    //virtual void onDrop() {}
    //virtual void onAttack(CWeapon *pWeapon) {}

    short int getHeight();
    short int getWidth();
    short int getDepth();

    void setHeight(int height);
    void setWidth(int width);
    void setDepth(int depth);

    void addEntityInBlock(CEntity *pEntity);
    void removeEntityFromBlock(CEntity *pEntity);
    bool hasEntitiesInBlock() const;
    bool isEntityInBlock(CEntity *pEntity) const;
    bool isEntityInBlock(const ENTITY_ID &nId) const;
    size_t getEntityCount() const;
    vector<CEntity*> getAllEntitiesInBlock() const;

    void setPickup(CPickup *pPickup);
    CPickup *getPickup() const;

    virtual void tick();

private:
    //CRepeat m_repeat;

    bool m_bBeingDestroyed;
    
    D3DXVECTOR3 m_vecPosition;
    const int m_nTileID;
    bool m_bDroppable;
    bool m_bWalkable;
    bool m_bDestructible;

    string m_szTextureName;

    short int m_nHeight;
    short int m_nWidth;
    short int m_nDepth;

    vector<CEntity*> m_arrEntities;

    CPickup *m_pPickup;
};

#endif